﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Business = SoTaiChinh.Library.Business;
using Entity = SoTaiChinh.Library.Entity;
using Commom = SoTaiChinh.Library.Common;

public partial class admin_login : System.Web.UI.Page
{
    Business.ThanhVien business = new Business.ThanhVien();
    Entity.ThanhVien entity = new Entity.ThanhVien();
    Commom.Cryption.MD5Cryption md5 = new Commom.Cryption.MD5Cryption();
    DataTable dtThanhVien = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            msgError.Style.Add("display", "none");
        }
    }
    protected void submit_Click(object sender, EventArgs e)
    {
        try
        {
            entity.TenDangNhap = txtTenDangNhap.Text;
            entity.MatKhau = md5.Encrypt(txtMatKhau.Text);
            dtThanhVien = business.LoginAdmin(entity);
            if (dtThanhVien.Rows.Count != 0)
            {
                if (Convert.ToInt32(dtThanhVien.Rows[0]["QuyenTruyCap"].ToString()) == 1 || Convert.ToInt32(dtThanhVien.Rows[0]["QuyenTruyCap"].ToString()) == 2)
                {
                    Session["user_login_admin"] = dtThanhVien.Rows[0]["TenDangNhap"].ToString();
                    msgError.Style.Add("display", "none");
                    Response.Redirect("default.aspx");
                }
                else
                {
                    msgError.Style.Add("display", "block");
                }
            }
            else
            {
                msgError.Style.Add("display", "block");
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
}
